package com.xtianzhuang.www.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xtianzhuang.www.controller.BaseController;
import com.xtianzhuang.www.dao.UserInfoMapper;
import com.xtianzhuang.www.entity.User;
import com.xtianzhuang.www.entity.UserInfo;
import com.xtianzhuang.www.entity.UserInfoExample;
import com.xtianzhuang.www.service.UserInfoService;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserInfoServiceImpl implements UserInfoService {
	private static Logger logger = Logger.getLogger(BaseController.class);
	@Autowired
	private UserInfoMapper dao;

	@Override
	public List<UserInfo> selectByExample(UserInfoExample example) {
		// TODO Auto-generated method stub
		return dao.selectByExample(example);
	}

	@Override
	public int insert(UserInfo record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean doUserLogin(User user) {
		// TODO Auto-generated method stub
		UserInfoExample example = new UserInfoExample();
		example.or().andUsernameEqualTo(user.getUsername());
		List<UserInfo> list = dao.selectByExample(example);
		if (list.size() > 0) {
			if (list.get(0).getPassword().equals(user.getPassword())) {
				return true;
			}
		}
		return false;
	}

	/*
	 * (非 Javadoc) <p>Title: insertList</p> <p>Description: </p>
	 * 
	 * @param recordList
	 * 
	 * @return
	 * 
	 * @see com.xtianzhuang.www.service.UserInfoService#insertList(java.util.List)
	 */
	@Override
	public int insertList(List<UserInfo> recordList) {
		// TODO Auto-generated method stub
		int count = 0;
		for (UserInfo item : recordList) {
			try {
				count += dao.insert(item);

			} catch (Exception e) {
				// TODO: handle exception
				logger.error("insert Exception{}" + e.getMessage());
				throw new RuntimeException();
			}

		}

		return count;
	}

}
